/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package multiversiontechnicaldocumentation;

import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.IOException;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author VadimBaitoiu
 */
public class MultiversionTechnicalDocumentation {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            // Set System L&F
            UIManager.setLookAndFeel(
                    UIManager.getSystemLookAndFeelClassName());
        } catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            System.err.println(e.getMessage());
        }

        // Acquiring the current Graphics Device and Graphics Configuration
        GraphicsEnvironment graphEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice graphDevice = graphEnv.getDefaultScreenDevice();
        GraphicsConfiguration graphicConf = graphDevice.getDefaultConfiguration();

        // init new window
        final MainFrame mainFrame = new MainFrame(graphicConf);
        mainFrame.setLocationByPlatform(true);
        mainFrame.setVisible(true);
        mainFrame.setFocusTraversalKeysEnabled(false);

        // run smoke test
        test(mainFrame);
    }

    private static void test(MainFrame mainFrame) {
        String path = "E:\\multiversion-technical-documentation\\sample.txt";
        Reader reader = new Reader();
        File file = new File(path);
        try {
            Document document = reader.read(file);

            Writer writer = new MVTDWriter();
            writer.open(path + ".mvtd");
            writer.write(document);
            writer.close();
            
            document.setCurrentVersion(document.getMostRecentVersion());
            writer = new HTMLWriter();
            writer.open(path + ".html");
            writer.write(document);
            writer.close();
            
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(mainFrame, ex.getMessage(), ex.getClass().
                    toString(), JOptionPane.ERROR_MESSAGE);
        } catch (DocumentStructureException | DocumentCommandException ex) {
            JOptionPane.showMessageDialog(mainFrame, ex.getMessage(), ex.getClass().
                    toString(), JOptionPane.ERROR_MESSAGE);
        }
    }
}
